<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>走读审批</title>
    <link href="../../static/css/bootstrap.min.css" rel="stylesheet" th:href="@{/static/css/bootstrap.min.css}">
    <!-- Custom styles for this template -->
    <link href="../../static/css/dashboard.css" rel="stylesheet" th:href="@{/static/css/dashboard.css}">
</head>
<body>
<div th:insert="admin/common::topbar"></div>
<div class="container-fluid">
    <div class="row">
        <div th:insert="~{admin/common::sidebar(active='operateDorm.html')}"></div>
        <main class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4" role="main">
            <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
                <h1 class="h3">走读审批</h1>
                <div class="btn-toolbar mb-2 mb-md-0">
                    <div class="btn-group mr-2">
                        <button class="btn btn-sm btn-outline-secondary" id="btn-applyDorm">住校审批</button>
                        <button class="btn btn-sm btn-outline-secondary" id="btn-stuDorm">住校学生</button>
                        <button class="btn btn-sm btn-outline-secondary" id="btn-update-Dorm-Application">换寝审批</button>
                    </div>
                    <div class="btn-group mr-2">
                        <button class="btn btn-primary btn-sm btn-outline-secondary" id="btn-admin">管理员</button>
                        <button class="btn btn-sm btn-outline-secondary" id="btn-student">学生端</button>
                    </div>
                </div>
            </div>
            <div th:switch="${size>0}">
                <div class="table-responsive" th:case="true">
                    <table class="table table-striped table-hover table-bordered table-sm">
                        <thead>
                        <tr>
                            <th>学号</th>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>申请</th>
                            <th>宿舍门牌</th>
                            <th>床位</th>
                            <th>申请理由</th>
                            <th>申请时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="list:${List}">
                            <th th:text="${list.getSno()}"></th>
                            <th th:text="${list.getSname()}"></th>
                            <th th:text="${list.getSex()}"></th>
                            <th th:text="${'走读申请'}"></th>
                            <th th:text="${list.getDormPlace()}"></th>
                            <th th:text="${list.getBed_id()}"></th>
                            <th th:text="${list.getReason()}"></th>
                            <th th:text="${list.getTime()}"></th>
                            <th>
                                <button class="btn btn-sm btn-success" id="btn-agree" th:value="${list.getSno()}">同意
                                </button>
                                <button class="btn btn-sm btn-warning" id="btn-refuse" th:value="${list.getSno()}">拒绝
                                </button>
                            </th>
                        </tr>
                        </tbody>

                    </table>
                </div>
                <div th:case="false">
                    <h1>暂无学生申请!</h1>
                </div>
            </div>
        </main>
    </div>
</div>
<script src="../../static/js/jquery-3.6.0.js" th:src="@{/static/js/jquery-3.6.0.js}"></script>
<script src="../../static/js/bootstrap.min.js" th:src="@{/static/js/bootstrap.min.js}" type="text/javascript"></script>
<script>
    $(function () {

        $('#btn-agree').click(function () {
            let sno = $('#btn-agree').val();
            console.log(sno);
            let judge = confirm("是否同意?");
            if (judge === true) {
                $.get({
                    url: "/admin/ajax/agreeApplication",
                    data: {"sno": sno},
                    success: function (result) {
                        if (result === true) {
                            alert("操作成功!");
                            $(location).attr('href', '/admin/getQuitStuDorm');
                        } else {
                            alert("操作失败!");
                        }
                    }
                })
            } else {

            }


        })
        $('#btn-refuse').click(function () {
            let sno = $('#btn-refuse').val();
            let judge = confirm("是否拒绝?");
            if (judge === true) {
                $.get({
                    url: "/admin/ajax/refuseApplication",
                    data: {"sno": sno},
                    success: function (result) {
                        if (result === true) {
                            alert("操作成功!");
                            $(location).attr('href', '/admin/getQuitStuDorm');
                        } else {
                            alert("操作失败!");
                        }
                    }
                })
            } else {

            }
        })
        $('#btn-update-Dorm-Application').click(function () {
            $(location).attr('href', '/admin/getUpdateStuDorm');
        })
        $('#btn-applyDorm').click(function () {
            $(location).attr('href', '/admin/getDormApplication');
        })
        $('#btn-stuDorm').click(function () {
            $(location).attr('href', '/admin/getStudentDorm/1/5');
        })
        $('#btn-admin').click(function () {
            let result = confirm("是否进入管理员登录?");
            if (result === true) {
                $(location).attr('href', '/adminLogin.html');
            } else {

            }

        })
        $('#btn-student').click(function () {
            let result = confirm("是否重新登录?");
            if (result === true) {
                $(location).attr('href', '/studentLogin.html');
            } else {

            }

        })
    })
</script>
</body>
</html>